home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / actlib13.zip / STRINGS.ZIP / RMSTR.C < prev    next >
Text File  |  1993-01-14  |  1KB  |  44 lines

  1. /*  Copyright (C) 1993   Marc Stern  (internet: stern@mble.philips.be)  */
  2.  
  3. #include "strings.h"
  4.  
  5. /***
  6.  *  Function    :  strrmstr
  7.  *
  8.  *  Description :  Removing all occurences of a target string.
  9.  *
  10.  *  Parameters  :  in/out   char  *string
  11.  *                 in       char  *target     target string to remove
  12.  *
  13.  *  Decisions   :  Same implementation as strmvstr without copying
  14.  *           a replacement string.
  15.  *           Could also be implemented as
  16.  *                        strmvstr( ptr, ptr, target, "" )
  17.  *           but should be less efficient.
  18.  *
  19.  *  Return code :  pointer to result.
  20.  *
  21.  *  OS/Compiler :  All
  22.  ***/
  23.  
  24. char *strrmstr( char *string, const char *target )
  25.  
  26. { char *ptr, *out;
  27.   unsigned count = 0;
  28.  
  29.   for ( out = ptr = string; *out = *ptr; out++, ptr ++ )
  30.       if ( *ptr == *target ) { target ++; count ++;
  31.                                if ( ! *target )
  32.                       { out -= count;
  33.                     target -= count;
  34.                   }
  35.                   }
  36.              else { target -= count;
  37.                     ptr -= count;
  38.                 out -= count;
  39.                 count = 0;
  40.                   }
  41.  
  42.   return string;
  43. }
  44.